package com.waves.task.controller;

import com.waves.core.annotation.MyLog;
import com.waves.core.web.domain.R;
import com.waves.core.web.domain.TableDataInfo;
import com.waves.task.domain.dto.TaskDTO;
import com.waves.task.domain.dto.TaskPageDTO;
import com.waves.task.domain.dto.TaskTestDTO;
import com.waves.task.domain.entity.TaskCopy;
import com.waves.task.domain.vo.TaskVO;
import com.waves.task.service.TaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

/**
 * 任务表控制层
 *
 * @author : dlw
 * @date : 2024-9-18
 */
@Api(tags = "任务表对象功能接口")
@RestController
@RequestMapping("/task")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TaskController {

    private final TaskService taskService;

    @ApiOperation(value = "分页查询任务帖子")
    @GetMapping("/page")
    @MyLog
    public TableDataInfo<TaskVO> page(TaskPageDTO dto) {
        return taskService.listTaskPage(dto);
    }

    @ApiOperation(value = "任务帖子查询详情")
    @GetMapping("/getTask/{id}")
    public R<TaskVO> getTask(@PathVariable long id) {
        return taskService.getTask(id);
    }

    @ApiOperation(value = "任务帖子新增")
    @PostMapping("/save")
    public R<Object> save(@RequestBody TaskDTO dto) {
        return taskService.saveTask(dto);
    }

    @ApiOperation(value = "任务帖子修改")
    @PostMapping("/update")
    public R<Object> update(@RequestBody TaskDTO dto) {
        return taskService.updateTask(dto);
    }

    @ApiOperation(value = "任务帖子删除")
    @DeleteMapping("/delete")
    public R<Object> delete(@RequestParam("taskId") Long taskId) {
        return R.ok(taskService.deleteTask(Collections.singletonList(taskId)));
    }

    @ApiOperation(value = "点赞/取消赞")
    @GetMapping("/likeTask/{id}")
    public R<Object> likeTask(@PathVariable long id) {
        return R.ok(taskService.likeTask(id));
    }

    @ApiOperation(value = "收藏/取消收藏")
    @GetMapping("/collectTask/{id}")
    public R<Object> collectTask(@PathVariable long id) {
        return R.ok(taskService.collectTask(id));
    }

    @ApiOperation(value = "任务完成、取消和领取")
    @GetMapping("/updateTaskStatus/{type}/{taskId}/{receiveId}")
    public R<Object> updateTaskStatus(@PathVariable Integer type,@PathVariable long taskId,@PathVariable long receiveId) {
        return taskService.updateTaskStatus(type,taskId,receiveId);
    }

    /**
     * 任务领取测试方法
     * @param dto
     * @return
     */
    @ApiOperation(value = "任务完成、取消和领取")
    @PostMapping("/updateTaskStatus2")
    public R<Object> updateTaskStatus2(@RequestBody TaskTestDTO dto) {
        return taskService.updateTaskStatus2(dto.getType(),dto.getTaskId(),dto.getReceiveId());
    }

    @ApiOperation(value = "数据测试")
    @GetMapping("/testTask/{id}")
    public R<List<TaskCopy>> testTask(@PathVariable Integer id) {
        return taskService.testTask(id);
    }

}
